package com.ruoyi.project.orderSystem.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.orderSystem.domain.WorkOrder;
import com.ruoyi.project.orderSystem.service.IWorkOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 工单Controller
 *
 * @author wangshuo
 * @date 2021-01-24
 */
@RestController
@RequestMapping("/orderSystem/workOrder")
public class WorkOrderController extends BaseController
{
    @Autowired
    private IWorkOrderService workOrderService;

    /**
     * 查询工单列表
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrder workOrder)
    {
        startPage();
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
        return getDataTable(list);
    }

    /**
     * 导出工单列表
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:export')")
    @Log(title = "工单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkOrder workOrder)
    {
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
        ExcelUtil<WorkOrder> util = new ExcelUtil<WorkOrder>(WorkOrder.class);
        return util.exportExcel(list, "workOrder");
    }

    /**
     * 获取工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workOrderService.selectWorkOrderById(id));
    }

    /**
     * 新增工单
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:add')")
    @Log(title = "工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrder workOrder)
    {
        return toAjax(workOrderService.insertWorkOrder(workOrder));
    }

    /**
     * 修改工单
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:edit')")
    @Log(title = "工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrder workOrder)
    {
        return toAjax(workOrderService.updateWorkOrder(workOrder));
    }

    /**
     * 删除工单
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:remove')")
    @Log(title = "工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workOrderService.deleteWorkOrderByIds(ids));
    }


    /**
     * 删除工单
     */
    @GetMapping("/getExecutorList")
    public AjaxResult getExecutorList()
    {
        return AjaxResult.success(workOrderService.getExecutorList());
    }

    /**
     * 获取工单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('orderSystem:workOrder:query')")
    @GetMapping(value = "/getWorkOrderStationList/{id}")
    public AjaxResult getWorkOrderStationList(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workOrderService.getWorkOrderStationList(id));
    }

    /**
     * 运维调度地图
     */
    @GetMapping(value = "/workOrderMap")
    public AjaxResult workOrderMap()
    {
        return AjaxResult.success(workOrderService.workOrderMap());
    }
}
